package com.careerraiser.testing;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeSet;

import com.careerraiser.child.Dog;
import com.careerraiser.child.Cat;
import com.careerraiser.child.SoundMaker;
import com.careerraiser.parent.Animal;

public class GenericsTest {

	public static void main(String[] args) {
List<Animal>anList=new ArrayList<Animal>();
Animal an1=new Dog();
List listcat=new ArrayList();
//even though line above is correct,
//below line will give you an error.
//ArrayList<Animal>anList1=new ArrayList<Dog>();

List<? extends Animal>anList3=new ArrayList<Dog>();
List<? extends Animal>anList2=new ArrayList<Cat>();
List<Dog> dogList = new LinkedList<Dog>();
Dog testDog=new Dog();
testDog.setName("testDog");
Cat testCat=new Cat();
anList.add(testDog);
anList.add(an1);
anList.add(testCat);
dogList.add(testDog);

//creating a list of interface
List<SoundMaker> intList=new ArrayList<SoundMaker>();
intList.add(testCat);
intList.add(testDog);

List <Animal> anreturn=(List<Animal>) testWildcard(anList);
System.out.println("---------------before loop-------");
for(int i=0; i<anreturn.size();i++){
	Animal animal=anreturn.get(i);
	System.out.println(animal.getName());

}
//both the for loops top and bottom achieve the same output.
for (Animal animal : anreturn) {
	System.out.println(animal.getName());
}
}

	public static List<? super Animal> testWildcard(List<? extends Animal> anmlList){
		Animal an1=anmlList.get(0);
		System.out.println(an1.getName());
		anmlList.remove(0);
		//anmlList.add(2, new Dog());
		List<Object> obj1=new ArrayList<Object>();
		//returning the obj1 list is dangerous for lists that check for Animal.
		//return obj1;
		return (List<Animal>) anmlList;
		 
	}
}
